package com.choosefine.it.basedata.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.basedata.model.SettleType;
import com.choosefine.it.basedata.service.SettleTypeService;
import com.choosefine.it.common.def.CommonConstant;

@Api(value="结算方式操作",description="鞠成阳")
@RestController
@RequestMapping("/database/settleType")
public class SettleTypeController extends BaseController {
	
	@Autowired
	public SettleTypeService settleTypeService;
	
	@ApiOperation(value="添加结算方式种类")
	@ApiImplicitParam(name = "settleTypeName", value = "结算方式名", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value="/{settleTypeName}",method=RequestMethod.POST)
	public String addSettleType(@PathVariable String settleTypeName)throws Exception{
		String result = null;
		Integer num = 0;
		SettleType settletype = new SettleType();
		settletype.setSettleTypeName(settleTypeName);
		settletype.setIsValid(CommonConstant.VALID);
		num = settleTypeService.insert(settletype);
		if(num>0){
			result = responseSuccess(num);
		}else{
			result = responseCreateFail();
		}
		return result;
	}
	
	@ApiOperation(value="查看所有结算方式")
	@RequestMapping(value="/selectSettleTypeList",method=RequestMethod.GET)
	public String selectSettleTypeList(){
		String result = null;
		List<SettleType>list = settleTypeService.selectAll();
		if(list!=null){
			result = responseArraySuccess(list);
		}else{
			result = responseFail();
		}
		return result;
	}
	@ApiOperation(value="根据结算方式Id删除结算方式")
	@RequestMapping(value="/deleteSettleType/{id}",method=RequestMethod.DELETE)
	public String deleteSettleType(@PathVariable Integer id){
		String result = null;
		Integer num = settleTypeService.updateSettleType(id);
		if(num!=0){
			result = responseSuccess(num);
		}else{
			result = responseFail();
		}
		return result;
	}
	@ApiOperation(value="根据结算方式Id修改结算方式")
	@RequestMapping(value="/updateSettleType/{id}",method=RequestMethod.PUT)
	public String updateSettleType(@RequestBody SettleType settleType){
		String result = null;
		Integer num = settleTypeService.updateSettleType(settleType);
		if(num!=0){
			result = responseSuccess(num);
		}else{
			result = responseCreateFail();
		}
		return result;
	}
}
